

#include <disp_manager.h>
#include <ui.h>
static int DefaultOnDraw(struct Button *ptButton, PDispBuff ptDispBuff)
{
	//绘制底色
	DrawRegion(&ptButton->tRegion,BUTTON_DEFAULT_COLOR);

	//居中写文字
	DrawTextInRegionCentral(ptButton->name,&ptButton->tRegion,BUTTON_TEXT_COLOR);

	
	/*flush to lcd/web*/
	FlushDisplayRegion(&ptButton->tRegion,ptDispBuff);

	return 0;
}

static	int DefaultOnPressed(struct Button *ptButton, PDispBuff ptDispBuff, PInputEvent ptInputEvent)
{
	unsigned int dwColor= BUTTON_DEFAULT_COLOR;
	//点击之后状态要翻转
	ptButton->status	=	!ptButton->status;
	if(ptButton->status)
		dwColor	=	BUTTON_PRESSED_COLOR;
	//绘制底色
	DrawRegion(&ptButton->tRegion,dwColor);

	//居中写文字
	DrawTextInRegionCentral(ptButton->name,&ptButton->tRegion,BUTTON_TEXT_COLOR);

	
	/*flush to lcd/web*/
	FlushDisplayRegion(&ptButton->tRegion,ptDispBuff);
	
	return 0;
}


void InitButton(PButton ptButton,char *name,PRegion ptRegion,ONDRAW_FUNC OnDraw,ONPRESSED_FUNC OnPressed)
{
	ptButton->name 		= name;
	if (ptRegion)
		ptButton->tRegion	= *ptRegion;
	ptButton->OnDraw	= OnDraw ? OnDraw : DefaultOnDraw;//这句话的意思是OnDraw是否存在，如果存在则传递的是OnDraw。否则传递的是DefaultOnDraw
	ptButton->OnPressed	= OnPressed ? OnPressed : DefaultOnPressed;
	ptButton->status	= 0;//初始状态等于0


}

